
<template>
  <div id="viewfile-box" class="viewfile-box">
    <iframe ref="iframe" class="iframe" :src="link" frameborder="0" />
  </div>
</template>
<script>
function addWaterMarker(str) {
  const can = document.createElement('canvas')
  can.width = 200
  can.height = 150

  const cans = can.getContext('2d')
  cans.rotate(-20 * Math.PI / 180)
  cans.font = '16px Vedana'
  cans.fillStyle = 'rgba(200, 200, 200, 0.20)'
  cans.textAlign = 'left'
  cans.textBaseline = 'Middle'
  cans.fillText(str, 0, can.height / 2)

  const div = document.createElement('div')
  const iframe = document.getElementById('viewfile-box')
  div.style.pointerEvents = 'none'
  div.style.top = '0'
  div.style.left = '0'
  div.style.right = '0'
  div.style.bottom = '0'

  div.style.position = 'absolute'
  div.style.zIndex = '1000'
  div.style.background = 'url(' + can.toDataURL('image/png') + ') left top repeat'
  iframe.appendChild(div)
}
export default {
  name: 'FrameLink',
  data() {
    return {
      link: ''
    }
  },
  computed: {
  },
  created() {
    this.link = `/slm-ctm/cdn/pdfJS/web/viewer.html?file=` + atob(this.$route.query.src)
  },
  mounted() {
    const iframe = this.$refs.iframe
    const waterTxt = `${this.userInfo.userName} ${this.userInfo.shopName}`
    if (iframe.attachEvent) {
      iframe.attachEvent('onload', () => {
        addWaterMarker(waterTxt)
      })
    } else {
      iframe.onload = () => {
        addWaterMarker(waterTxt)
      }
    }
  },
  methods: {}
}

</script>
<style scoped lang='scss'>
  .viewfile-box {
    overflow: hidden;
    position: relative;
  }

  .iframe {
    width: 100%;
    height: 100vh;
    border: 0;
    overflow: hidden;
    box-sizing: border-box;
  }

</style>
